package wafa.clientJms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import wafa.exceptions.AFamilyNotFound;
import wafa.gedInterface.Service;
import wafa.modelDocument.Document;

public class ClientJms implements Service,MessageListener {
	private JmsTemplate jmsTemplate;




	@Override
	public void addDocument(final Document document) throws AFamilyNotFound {
		// TODO Auto-generated method stub
		
		System.out.println("ok");

		jmsTemplate.send(new MessageCreator() {
			public Message createMessage(final Session session)
					throws JMSException {
				return session.createObjectMessage(document);
			}
		});	
	}
	
	
	
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}

	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}



	@Override
	public void onMessage(Message message) {
		// TODO Auto-generated method stub
		
		
		
		try {
			System.out.println("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"+message.getJMSCorrelationID());
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}

}
